package com.briup.ch10;

/**
 * @Author briup-adam
 * @Date 2023/10/26 下午6:01
 * @Description
 **/

public class JoinTest {
    public static void main(String[] args) {
//        创建子线程1，每隔10ms输出1-40
        Thread t1=new Thread(){
            @Override
            public void run() {
                for (int i = 1; i <=40 ; i++) {
                    System.out.println(i);
                    try {
                        sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        //创建子线程2，每隔10ms输出100-70
        Thread t2=new Thread(()->{
            for (int i = 100; i >=70 ; i--) {
                if (i==80){
                    try {
                        //t2阻塞  等到t1结束
//                        t1.join();
                        //t2阻塞  等t1 50ms
                        t1.join(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(i);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();
    }
}
